//
//  HYLViewController.m
//  qq通信
//
//  Created by hyl on 16/6/2.
//  Copyright © 2016年 hyl. All rights reserved.
//

#import "HYLViewController.h"
#import "HYLChat.h"
#import "HYLChatCell.h"
@interface HYLViewController () <UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong,nonatomic) NSArray *messages;
@end

@implementation HYLViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.dataSource=self;
    self.tableView.delegate=self;
    //self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
}
#pragma mark - setter/getter
-(NSArray *) messages{
    if (_messages==nil) {
        NSString *path=[[NSBundle mainBundle]pathForResource:@"messages.plist" ofType:nil];
        NSArray *ArrMessage=[NSArray arrayWithContentsOfFile:path];
        NSMutableArray *ArrM=[NSMutableArray array];
        for (NSDictionary *dic in ArrMessage) {
            [ArrM addObject:[HYLChat chatWithDic:dic]];
        }
        _messages=ArrM;
    }
    return  _messages;
}

#pragma mark - UITableViewDataSource
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.messages.count;
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HYLChatCell *cell=[HYLChatCell chatCell:tableView];
    cell.chat=self.messages[indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate
-(CGFloat) tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return [self.messages[indexPath.row] cellHight];
}
@end
